using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using Zero.Entity.Models;
using Zero.Entity.Models.Mapping;

namespace Zero.Data
{
    public class ZeroContext : DbContext
    {
        static ZeroContext()
        {
            Database.SetInitializer<ZeroContext>(new ZeroInitializer());
            //Database.SetInitializer<ZeroContext>(null);
        }

		public ZeroContext()
			: base("Name=ZeroContext")
		{
		}

        public DbSet<CF_Role> CF_Role { get; set; }
        public DbSet<CF_User> CF_User { get; set; }

        public DbSet<CF_Privilege> CF_Privilege { get; set; }
      
        public DbSet<Sys_Button> Sys_Button { get; set; }
        public DbSet<Sys_ButtonClass> Sys_ButtonClass { get; set; }
        public DbSet<Sys_Menu> Sys_Menu { get; set; }

        public virtual void Commit()
        {
            base.SaveChanges();
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new CF_RoleMap());
            modelBuilder.Configurations.Add(new CF_UserMap());

            modelBuilder.Configurations.Add(new CF_PrivilegeMap());

            modelBuilder.Configurations.Add(new Sys_ButtonMap());
            modelBuilder.Configurations.Add(new Sys_ButtonClassMap());
            modelBuilder.Configurations.Add(new Sys_MenuMap());
            
        }
    }
}
